/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package utn.frsf.cidisi.upcolbpip.b2bcollaborations.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import utn.frsf.cidisi.upcolbpip.b2bcollaborations.B2BCollaboration;
import utn.frsf.cidisi.upcolbpip.b2bcollaborations.B2BRelationship;
import utn.frsf.cidisi.upcolbpip.b2bcollaborations.B2bcollaborationsPackage;
import utn.frsf.cidisi.upcolbpip.b2bcollaborations.BusinessDocument;
import utn.frsf.cidisi.upcolbpip.b2bcollaborations.BusinessDocumentType;
import utn.frsf.cidisi.upcolbpip.b2bcollaborations.CollaborativeAgreement;
import utn.frsf.cidisi.upcolbpip.b2bcollaborations.PartnerRole;
import utn.frsf.cidisi.upcolbpip.b2bcollaborations.TradingPartner;

import utn.frsf.cidisi.upcolbpip.businessinterfaces.BusinessInterface;

import utn.frsf.cidisi.upcolbpip.collaborativebusinessprocesses.CollaborativeBusinessProcess;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>B2B Collaboration</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.b2bcollaborations.impl.B2BCollaborationImpl#getName <em>Name</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.b2bcollaborations.impl.B2BCollaborationImpl#getDefinedBy <em>Defined By</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.b2bcollaborations.impl.B2BCollaborationImpl#getPartners <em>Partners</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.b2bcollaborations.impl.B2BCollaborationImpl#getParticipatingRoles <em>Participating Roles</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.b2bcollaborations.impl.B2BCollaborationImpl#getRelationship <em>Relationship</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.b2bcollaborations.impl.B2BCollaborationImpl#getProcesses <em>Processes</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.b2bcollaborations.impl.B2BCollaborationImpl#getDocumentTypes <em>Document Types</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.b2bcollaborations.impl.B2BCollaborationImpl#getDocuments <em>Documents</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.b2bcollaborations.impl.B2BCollaborationImpl#getBusinessInterfaces <em>Business Interfaces</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class B2BCollaborationImpl extends EObjectImpl implements B2BCollaboration {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getDefinedBy() <em>Defined By</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDefinedBy()
	 * @generated
	 * @ordered
	 */
	protected CollaborativeAgreement definedBy;

	/**
	 * The cached value of the '{@link #getPartners() <em>Partners</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPartners()
	 * @generated
	 * @ordered
	 */
	protected EList<TradingPartner> partners;

	/**
	 * The cached value of the '{@link #getParticipatingRoles() <em>Participating Roles</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParticipatingRoles()
	 * @generated
	 * @ordered
	 */
	protected EList<PartnerRole> participatingRoles;

	/**
	 * The cached value of the '{@link #getRelationship() <em>Relationship</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRelationship()
	 * @generated
	 * @ordered
	 */
	protected EList<B2BRelationship> relationship;

	/**
	 * The cached value of the '{@link #getProcesses() <em>Processes</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProcesses()
	 * @generated
	 * @ordered
	 */
	protected EList<CollaborativeBusinessProcess> processes;

	/**
	 * The cached value of the '{@link #getDocumentTypes() <em>Document Types</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDocumentTypes()
	 * @generated
	 * @ordered
	 */
	protected EList<BusinessDocumentType> documentTypes;

	/**
	 * The cached value of the '{@link #getDocuments() <em>Documents</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDocuments()
	 * @generated
	 * @ordered
	 */
	protected EList<BusinessDocument> documents;

	/**
	 * The cached value of the '{@link #getBusinessInterfaces() <em>Business Interfaces</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBusinessInterfaces()
	 * @generated
	 * @ordered
	 */
	protected EList<BusinessInterface> businessInterfaces;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected B2BCollaborationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return B2bcollaborationsPackage.Literals.B2B_COLLABORATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, B2bcollaborationsPackage.B2B_COLLABORATION__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CollaborativeAgreement getDefinedBy() {
		return definedBy;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetDefinedBy(CollaborativeAgreement newDefinedBy, NotificationChain msgs) {
		CollaborativeAgreement oldDefinedBy = definedBy;
		definedBy = newDefinedBy;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, B2bcollaborationsPackage.B2B_COLLABORATION__DEFINED_BY, oldDefinedBy, newDefinedBy);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDefinedBy(CollaborativeAgreement newDefinedBy) {
		if (newDefinedBy != definedBy) {
			NotificationChain msgs = null;
			if (definedBy != null)
				msgs = ((InternalEObject)definedBy).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - B2bcollaborationsPackage.B2B_COLLABORATION__DEFINED_BY, null, msgs);
			if (newDefinedBy != null)
				msgs = ((InternalEObject)newDefinedBy).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - B2bcollaborationsPackage.B2B_COLLABORATION__DEFINED_BY, null, msgs);
			msgs = basicSetDefinedBy(newDefinedBy, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, B2bcollaborationsPackage.B2B_COLLABORATION__DEFINED_BY, newDefinedBy, newDefinedBy));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<TradingPartner> getPartners() {
		if (partners == null) {
			partners = new EObjectContainmentEList<TradingPartner>(TradingPartner.class, this, B2bcollaborationsPackage.B2B_COLLABORATION__PARTNERS);
		}
		return partners;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PartnerRole> getParticipatingRoles() {
		if (participatingRoles == null) {
			participatingRoles = new EObjectContainmentEList<PartnerRole>(PartnerRole.class, this, B2bcollaborationsPackage.B2B_COLLABORATION__PARTICIPATING_ROLES);
		}
		return participatingRoles;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<B2BRelationship> getRelationship() {
		if (relationship == null) {
			relationship = new EObjectContainmentEList<B2BRelationship>(B2BRelationship.class, this, B2bcollaborationsPackage.B2B_COLLABORATION__RELATIONSHIP);
		}
		return relationship;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<CollaborativeBusinessProcess> getProcesses() {
		if (processes == null) {
			processes = new EObjectContainmentEList<CollaborativeBusinessProcess>(CollaborativeBusinessProcess.class, this, B2bcollaborationsPackage.B2B_COLLABORATION__PROCESSES);
		}
		return processes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<BusinessDocumentType> getDocumentTypes() {
		if (documentTypes == null) {
			documentTypes = new EObjectContainmentEList<BusinessDocumentType>(BusinessDocumentType.class, this, B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENT_TYPES);
		}
		return documentTypes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<BusinessDocument> getDocuments() {
		if (documents == null) {
			documents = new EObjectContainmentEList<BusinessDocument>(BusinessDocument.class, this, B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENTS);
		}
		return documents;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<BusinessInterface> getBusinessInterfaces() {
		if (businessInterfaces == null) {
			businessInterfaces = new EObjectContainmentEList<BusinessInterface>(BusinessInterface.class, this, B2bcollaborationsPackage.B2B_COLLABORATION__BUSINESS_INTERFACES);
		}
		return businessInterfaces;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case B2bcollaborationsPackage.B2B_COLLABORATION__DEFINED_BY:
				return basicSetDefinedBy(null, msgs);
			case B2bcollaborationsPackage.B2B_COLLABORATION__PARTNERS:
				return ((InternalEList<?>)getPartners()).basicRemove(otherEnd, msgs);
			case B2bcollaborationsPackage.B2B_COLLABORATION__PARTICIPATING_ROLES:
				return ((InternalEList<?>)getParticipatingRoles()).basicRemove(otherEnd, msgs);
			case B2bcollaborationsPackage.B2B_COLLABORATION__RELATIONSHIP:
				return ((InternalEList<?>)getRelationship()).basicRemove(otherEnd, msgs);
			case B2bcollaborationsPackage.B2B_COLLABORATION__PROCESSES:
				return ((InternalEList<?>)getProcesses()).basicRemove(otherEnd, msgs);
			case B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENT_TYPES:
				return ((InternalEList<?>)getDocumentTypes()).basicRemove(otherEnd, msgs);
			case B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENTS:
				return ((InternalEList<?>)getDocuments()).basicRemove(otherEnd, msgs);
			case B2bcollaborationsPackage.B2B_COLLABORATION__BUSINESS_INTERFACES:
				return ((InternalEList<?>)getBusinessInterfaces()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case B2bcollaborationsPackage.B2B_COLLABORATION__NAME:
				return getName();
			case B2bcollaborationsPackage.B2B_COLLABORATION__DEFINED_BY:
				return getDefinedBy();
			case B2bcollaborationsPackage.B2B_COLLABORATION__PARTNERS:
				return getPartners();
			case B2bcollaborationsPackage.B2B_COLLABORATION__PARTICIPATING_ROLES:
				return getParticipatingRoles();
			case B2bcollaborationsPackage.B2B_COLLABORATION__RELATIONSHIP:
				return getRelationship();
			case B2bcollaborationsPackage.B2B_COLLABORATION__PROCESSES:
				return getProcesses();
			case B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENT_TYPES:
				return getDocumentTypes();
			case B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENTS:
				return getDocuments();
			case B2bcollaborationsPackage.B2B_COLLABORATION__BUSINESS_INTERFACES:
				return getBusinessInterfaces();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case B2bcollaborationsPackage.B2B_COLLABORATION__NAME:
				setName((String)newValue);
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__DEFINED_BY:
				setDefinedBy((CollaborativeAgreement)newValue);
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__PARTNERS:
				getPartners().clear();
				getPartners().addAll((Collection<? extends TradingPartner>)newValue);
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__PARTICIPATING_ROLES:
				getParticipatingRoles().clear();
				getParticipatingRoles().addAll((Collection<? extends PartnerRole>)newValue);
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__RELATIONSHIP:
				getRelationship().clear();
				getRelationship().addAll((Collection<? extends B2BRelationship>)newValue);
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__PROCESSES:
				getProcesses().clear();
				getProcesses().addAll((Collection<? extends CollaborativeBusinessProcess>)newValue);
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENT_TYPES:
				getDocumentTypes().clear();
				getDocumentTypes().addAll((Collection<? extends BusinessDocumentType>)newValue);
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENTS:
				getDocuments().clear();
				getDocuments().addAll((Collection<? extends BusinessDocument>)newValue);
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__BUSINESS_INTERFACES:
				getBusinessInterfaces().clear();
				getBusinessInterfaces().addAll((Collection<? extends BusinessInterface>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case B2bcollaborationsPackage.B2B_COLLABORATION__NAME:
				setName(NAME_EDEFAULT);
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__DEFINED_BY:
				setDefinedBy((CollaborativeAgreement)null);
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__PARTNERS:
				getPartners().clear();
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__PARTICIPATING_ROLES:
				getParticipatingRoles().clear();
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__RELATIONSHIP:
				getRelationship().clear();
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__PROCESSES:
				getProcesses().clear();
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENT_TYPES:
				getDocumentTypes().clear();
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENTS:
				getDocuments().clear();
				return;
			case B2bcollaborationsPackage.B2B_COLLABORATION__BUSINESS_INTERFACES:
				getBusinessInterfaces().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case B2bcollaborationsPackage.B2B_COLLABORATION__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case B2bcollaborationsPackage.B2B_COLLABORATION__DEFINED_BY:
				return definedBy != null;
			case B2bcollaborationsPackage.B2B_COLLABORATION__PARTNERS:
				return partners != null && !partners.isEmpty();
			case B2bcollaborationsPackage.B2B_COLLABORATION__PARTICIPATING_ROLES:
				return participatingRoles != null && !participatingRoles.isEmpty();
			case B2bcollaborationsPackage.B2B_COLLABORATION__RELATIONSHIP:
				return relationship != null && !relationship.isEmpty();
			case B2bcollaborationsPackage.B2B_COLLABORATION__PROCESSES:
				return processes != null && !processes.isEmpty();
			case B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENT_TYPES:
				return documentTypes != null && !documentTypes.isEmpty();
			case B2bcollaborationsPackage.B2B_COLLABORATION__DOCUMENTS:
				return documents != null && !documents.isEmpty();
			case B2bcollaborationsPackage.B2B_COLLABORATION__BUSINESS_INTERFACES:
				return businessInterfaces != null && !businessInterfaces.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //B2BCollaborationImpl
